//
//  CLTabBarController.swift
//  WeiBo
//
//  Created by 程雷 on 2017/1/4.
//  Copyright © 2017年 chenglei. All rights reserved.
//

import UIKit

class CLTabBarController: UITabBarController {

    override func viewDidLoad() {
        super.viewDidLoad()
        
        let clTabBar = CLTabBar()
        
        clTabBar.composeClosure = {
        
            print("helloWord")
        }
        
        self.setValue(clTabBar, forKey: "tabBar")
        
        addChildViewControllers()
    }
    
    
    private func addChildViewControllers(){
        
        addChildViewController(vc: CLHomeTableViewController(), title: "首页", imageName: "tabbar_home")
        
        addChildViewController(vc: CLDiscoverTableViewController(), title: "消息", imageName: "tabbar_message_center")
        
        addChildViewController(vc: CLMessageTableViewController(), title: "发现", imageName: "tabbar_discover")
        
        addChildViewController(vc: CLProfileTableViewController(), title: "我的", imageName: "tabbar_profile")
    }
    
    
    
    private func addChildViewController(vc: UIViewController ,title: String ,imageName: String) {
        
        let nav = CLBaseNavController(rootViewController:vc)
        
        
        vc.title = title
        vc.tabBarItem.image = UIImage(named: imageName)
        vc.tabBarItem.selectedImage = UIImage(named: imageName + "_selected")?.withRenderingMode(.alwaysOriginal)
        vc.tabBarItem.setTitleTextAttributes([NSForegroundColorAttributeName : UIColor.orange], for: .selected)
        vc.tabBarItem.titlePositionAdjustment = UIOffset(horizontal: 0, vertical: -3)
        
       addChildViewController(nav)
        
        
        
    }
    
}
